from django.db import models
from django.utils import timezone


# Create your models here.


class User(models.Model):
    user_id = models.AutoField(primary_key=True)
    user_name = models.CharField(verbose_name="用户名", max_length=20)
    password = models.CharField(verbose_name="用户密码", max_length=15)
    email = models.EmailField(max_length=255)
    user_birthday = models.DateField(blank=True, null=True)
    user_age = models.IntegerField(blank=True, null=True)
    address = models.CharField(max_length=255, null=True, blank=True)
    phone = models.CharField(max_length=11)
    # 用户简介
    introduce = models.CharField(max_length=255, blank=True, null=True, default="向其他小伙伴介绍一下你自己吧")

    def __str__(self):
        return self.user_name

    class Meta:
        db_table = 'user'


# 验证码表（用于存放验证码）
class Code(models.Model):
    # 验证码id
    code_id = models.AutoField(primary_key=True)
    # 用户邮箱
    user_email = models.EmailField(max_length=255)
    # 验证码
    code = models.CharField(max_length=10)
    # 时间
    create_time = models.DateTimeField(blank=True)
    # 目前状况，1为未被使用，0为已经使用
    status = models.IntegerField(blank=True, default=1)

    def __str__(self):
        return self.code

    class Meta:
        db_table = 'code'


# 通知表
class Notification(models.Model):
    # 接收人id
    recipient_id = models.AutoField(primary_key=True)
    # 发送人id
    sender_id = models.BigIntegerField()
    # 发送内容
    send_content = models.TextField()
    # 发送时间
    send_time = models.DateTimeField(default=timezone.now)
    # 是否已读
    is_read = models.BooleanField(default=False)

    class Meta:
        db_table = 'Notification'


# 用户通知中间表
class Notification_user(models.Model):
    # 自增id
    notification_user_id = models.AutoField(primary_key=True)
    # 通知用户
    sender_id = models.BigIntegerField()
    # 接受用户
    recipient_id = models.BigIntegerField()

    class Meta:
        db_table = 'Notification_user'


# 关注表
class Follow(models.Model):
    # 自增id
    follow_id = models.AutoField(primary_key=True)
    # 关注的人
    following = models.CharField(max_length=255)
    # 被关注的人
    followed = models.CharField(max_length=255)
    # 创建时间
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'Follow'


# 用户关注表（多对多中间表）
class Follow_user(models.Model):
    # 自增id
    follow_user_id = models.AutoField(primary_key=True)
    # 关注表
    follow_id = models.BigIntegerField()
    # 用户表
    user_id = models.BigIntegerField()

    class Meta:
        db_table = 'Follow_user'
